//
//  CQModel.h
//  Pods
//
//  Created by green on 16/5/22.
//
//
#import <Foundation/Foundation.h>
#import <OpenGLES/ES2/glext.h>
#import <GLKit/GLKit.h>
#import "OpenGLProgram.h"
#import "CQVideoPlayer.h"

#define kAPositionName @"a_position"
#define kAColorName @"a_color"
#define kATextureCoordName @"a_textureCoord"

#define kUMVPName @"u_mvp"
#define kUSamplerBGName @"u_SamplerBG"
#define kUSamplerYName @"u_SamplerY"
#define kUSamplerUVName @"u_SamplerUV"

#define kUColorConversionMatrix @"u_colorConversionMatrix"

#define kUIsVideoName @"u_IsVideo"
#define kUIsImageName @"u_IsImage"
#define kUIsColorName @"u_IsColor"

enum {
    ATTRIBUTE_POSITION,
    ATTRIBUTE_COLOR,
    ATTRIBUTE_TEXCOORD,
    NUM_ATTRIBUTES
};

enum {
    UNIFORM_MVP,
    UNIFORM_SAMPLER_BG,
    UNIFORM_SAMPLER_Y,
    UNIFORM_SAMPLER_UV,
    UNIFORM_COLOR_CONVERSION_MATRIX,
    UNIFORM_IS_VIDEO,
    UNIFORM_IS_IMAGE,
    UNIFORM_IS_COLOR,
    NUM_UNIFORMS
};

@class CQModel;
/**
 *  委托
 */
@protocol CQModelDelegate<NSObject>
@optional

- (void)configureModelViewMatrixForModel:(CQModel *) model;

@end

/**
 *  模型超类
 */
@interface CQModel : NSObject

// 逆时针公转
@property (nonatomic, assign) float yaw;
@property (nonatomic, assign) float pitch;

// 缩放
@property (nonatomic, assign) float sx;
@property (nonatomic, assign) float sy;
@property (nonatomic, assign) float sz;

// 平移
@property (nonatomic, assign) float tx;
@property (nonatomic, assign) float ty;
@property (nonatomic, assign) float tz;

// 逆时针自转
@property (nonatomic, assign) float rx;
@property (nonatomic, assign) float ry;
@property (nonatomic, assign) float rz;

@property (nonatomic, strong) UIColor *backgroundColor;
@property (nonatomic, copy) NSString *backgroundImgFilePath;

@property (strong, nonatomic) OpenGLProgram *program;
@property (nonatomic, assign) GLKMatrix4 mvp;

@property (nonatomic, strong) CQVideoPlayer *videoPalyer;
@property (nonatomic, weak) id <CQModelDelegate> delegate;

- (void)setup;
- (void)updateWithMVP: (GLKMatrix4)mvp;
- (void)draw;
- (void)free;

- (void)setupPositionBuffer:(GLuint*)buffer positonAttrib:(GLuint)attrib;
- (void)setupTextureBuffer:(GLuint*)buffer textureAttrib:(GLuint)attrib;
- (void)setupElementBuffer:(GLuint*)buffer elementCount:(GLsizei *)count;

@end
